import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  ConflictException,
  NotFoundException,
} from '@nestjs/common';
import { RoleService } from './role.service';
import { CreateRoleDto } from './dto/create-role.dto';
import { UpdateRoleDto } from './dto/update-role.dto';
import {
  ApiOperation,
  ApiProperty,
  ApiTags,
  ApiCreatedResponse,
  ApiResponse,
  ApiBearerAuth,
  ApiQuery,
} from '@nestjs/swagger';
import { Permission } from '../permission/entities/permission.entity';
import { Public } from '../common/isPublic';

@ApiTags('角色信息')
@Controller('role')
@Public()
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @Post()
  @ApiOperation({ summary: '添加新角色' })
  @ApiProperty({ type: CreateRoleDto })
  @ApiCreatedResponse({ description: '角色创建成功', type: CreateRoleDto })
  @ApiBearerAuth() // 表示这个端点需要认证
  create(@Body() createRoleDto: CreateRoleDto) {
    return this.roleService.create(createRoleDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有角色' })
  @ApiResponse({
    status: 200,
    description: '角色列表返回成功',
  })
  findAll() {
    return this.roleService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取单个角色' })
  @ApiResponse({
    status: 200,
    description: '角色信息返回成功',
    type: CreateRoleDto,
  })
  @ApiResponse({ status: 404, description: '角色不存在' })
  findOne(@Param('id') id: string) {
    return this.roleService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新指定角色信息' })
  @ApiProperty({ type: UpdateRoleDto })
  @ApiResponse({
    status: 200,
    description: '角色更新成功',
    type: UpdateRoleDto,
  })
  update(@Param('id') id: string, @Body() updateRoleDto: UpdateRoleDto) {
    return this.roleService.update(id, updateRoleDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除指定角色' })
  @ApiResponse({ status: 200, description: '角色删除成功' })
  @ApiResponse({ status: 404, description: '角色不存在' })
  remove(@Param('id') id: string) {
    return this.roleService.remove(id);
  }
}
